<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建医保缴费登记</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>缴费主题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="title" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>缴费月份</label>
                        <div class="layui-input-block">
                            <input type="text" name="month" id="month" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ym">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">本月总计缴费(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" readonly  placeholder="自动按明细合计" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>


        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>缴费明细</span></div>
                        <div>
                            <button type="button" onclick="ctrlv_data_open()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">粘贴新增</button>
                            <button type="button" onclick="import_list()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">Excel导入</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_copy_row">复制行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <div style="overflow: auto">
                        <div style="width: 2500px;overflow: hidden">
                            <table class="layui-table" lay-size="sm">
                                <thead>
                                <tr>
                                    <th width="45">序号</th>
                                    <th><text>*</text>姓名</th>
                                    <th><text>*</text>身份证号码</th>
                                    <th>人数</th>
                                    <th>月数</th>
                                    <th>基数</th>
                                    <th>医保个人缴</th>
                                    <th>医保公缴</th>
                                    <th>大额个人</th>
                                    <th>大额公缴</th>
                                    <th>利息、滞纳金</th>
                                    <th>公缴小计</th>
                                    <th>个人小计</th>
                                    <th>缴费小计</th>
                                    <th>备注</th>
                                </tr>
                                </thead>
                                <tbody class="short_table_tbody" id="list_list"></tbody>
                            </table>

                        </div>
                    </div>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>


    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            title: {required: true},
            month: {required: true},
        },
        messages:{
            title: {required: "请输入"},
            month: {required: "请选择"},
        }
    });
    function import_list() {
        openPage('../public/import.php?reveal=cert_cure@importdata', '770px', '490px');
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_cert_cure_add}).done(function(res){
            if (res.code === 2000) {

                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><input type="text" class="layui-input name"></td>';
                listAddStr += '<td><input type="text" class="layui-input idcard"></td>';
                listAddStr += '<td><input type="number" class="layui-input renshu"></td>';
                listAddStr += '<td><input type="number" class="layui-input yueshu"></td>';
                listAddStr += '<td><input type="number" class="layui-input jsfee"></td>';
                listAddStr += '<td><input type="number" class="layui-input ygefee"></td>';
                listAddStr += '<td><input type="number" class="layui-input ygongfee"></td>';
                listAddStr += '<td><input type="number" class="layui-input dgefee"></td>';
                listAddStr += '<td><input type="number" class="layui-input dgongfee"></td>';
                listAddStr += '<td><input type="number" class="layui-input zhifee"></td>';
                listAddStr += '<td><input type="number" class="layui-input gonghe"></td>';
                listAddStr += '<td><input type="number" class="layui-input gehe"></td>';
                listAddStr += '<td><input type="number" class="layui-input money"></td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 1);
                update_refresh_row_func();


                public_upload_file_load('upload_files');
                initParseMoney();
                render_from();
            }
        });



        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}



            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var name = $(this).find('.name').val();
                    var idcard = $(this).find('.idcard').val();
                    var renshu = $(this).find('.renshu').val();
                    var yueshu = $(this).find('.yueshu').val();
                    var jsfee = $(this).find('.jsfee').val();
                    var ygefee = $(this).find('.ygefee').val();
                    var ygongfee = $(this).find('.ygongfee').val();
                    var dgefee = $(this).find('.dgefee').val();
                    var dgongfee = $(this).find('.dgongfee').val();
                    var zhifee = $(this).find('.zhifee').val();
                    var gonghe = $(this).find('.gonghe').val();
                    var gehe = $(this).find('.gehe').val();
                    var money = $(this).find('.money').val();
                    var explain = $(this).find('.explain').val();


                    var index = i + 1;
                    if(!name){
                        throw new Error('第'+index+'行，请输入姓名');
                    }

                    list.push({
                        name:name,
                        idcard:idcard,
                        renshu:renshu,
                        yueshu:yueshu,
                        jsfee:jsfee,
                        ygefee:ygefee,
                        ygongfee:ygongfee,
                        dgefee:dgefee,
                        dgongfee:dgongfee,
                        zhifee:zhifee,
                        gonghe:gonghe,
                        gehe:gehe,
                        money:money,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;

            data = parseMoney(data);

            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_cert_cure_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });



    $('#list_list').on('input propertychange','.money',function () {
        jisuan_money_all();
    });
    function jisuan_money_all() {
        var allmoney = 0;
        $('#list_list tr').each(function (i) {
            var money = parseValidNum($(this).find('.money').val());
            allmoney = parseFloat(allmoney) + parseFloat(money);
        });
        $("#money").val(allmoney);
        initParseMoney();
    }

    function update_refresh_row_func() {
        render_date();
        render_from();
        jisuan_money_all();

        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }




    var ctrlv_field_name = [
        {field: 'name', name:'姓名'},
        {field: 'idcard', name:'身份证号码'},
        {field: 'renshu', name:'人数',type:'number'},
        {field: 'yueshu', name:'月数',type:'number'},
        {field: 'jsfee', name:'基数',type:'number'},
        {field: 'ygefee', name:'医保个人缴',type:'number'},
        {field: 'ygongfee', name:'医保公缴',type:'number'},
        {field: 'dgefee', name:'大额个人',type:'number'},
        {field: 'dgongfee', name:'大额公缴',type:'number'},
        {field: 'zhifee', name:'利息、滞纳金',type:'number'},
        {field: 'gonghe', name:'公缴小计',type:'number'},
        {field: 'gehe', name:'个人小计',type:'number'},
        {field: 'money', name:'缴费小计',type:'number'},
        {field: 'explain', name:'备注'},
    ];
    function ctrlv_data_show(list) {
        if(list.length > 0){
            var nums = $("#list_list tr").length;
            for (var key in list){
                var str = '';
                nums++;
                str += '<tr>';
                str += '<td style="width: 45px">'+nums+'</td>';
                str += '<td><input type="text" class="layui-input name" value="'+list[key].name+'"></td>';
                str += '<td><input type="text" class="layui-input idcard" value="'+list[key].idcard+'"></td>';
                str += '<td><input type="text" class="layui-input renshu" value="'+list[key].renshu+'"></td>';
                str += '<td><input type="number" class="layui-input yueshu" value="'+list[key].yueshu+'"></td>';
                str += '<td><input type="number" class="layui-input jsfee" value="'+list[key].jsfee+'"></td>';
                str += '<td><input type="number" class="layui-input ygefee" value="'+list[key].ygefee+'"></td>';
                str += '<td><input type="number" class="layui-input ygongfee" value="'+list[key].ygongfee+'"></td>';
                str += '<td><input type="number" class="layui-input dgefee" value="'+list[key].dgefee+'"></td>';
                str += '<td><input type="number" class="layui-input dgongfee" value="'+list[key].dgongfee+'"></td>';
                str += '<td><input type="number" class="layui-input zhifee" value="'+list[key].zhifee+'"></td>';
                str += '<td><input type="number" class="layui-input gonghe" value="'+list[key].gonghe+'"></td>';
                str += '<td><input type="number" class="layui-input gehe" value="'+list[key].gehe+'"></td>';
                str += '<td><input type="number" class="layui-input money" value="'+list[key].money+'"></td>';
                str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                str += '</tr>';
                $("#list_list").append(str);
            }
        }
        update_refresh_row_func();
        render_date();
        render_from();
    }

</script>
</body>
</html>
